package com.llj.Road_curve_measuring_system.module.History;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.View;


import com.chad.library.adapter.base.BaseQuickAdapter;
import com.llj.Road_curve_measuring_system.R;
import com.llj.Road_curve_measuring_system.adapter.ResultAdapter;
import com.llj.Road_curve_measuring_system.base.BaseActivity;
import com.llj.Road_curve_measuring_system.bean.ScreenResult;
import com.llj.Road_curve_measuring_system.common.GlobalConstant;
import com.llj.Road_curve_measuring_system.databinding.ActivityHistoryBinding;
import com.llj.Road_curve_measuring_system.module.input.InputModel;
import com.llj.Road_curve_measuring_system.module.results.ResultActivity;
import com.llj.Road_curve_measuring_system.util.ActivityUtil;
import com.llj.Road_curve_measuring_system.util.MyUtil;
import com.llj.Road_curve_measuring_system.util.ToastUtil;

import java.util.ArrayList;
import java.util.List;

public class HistoryActivity extends BaseActivity<HistoryPresenter> implements HistoryView {

    protected ActivityHistoryBinding binding;
    private ResultAdapter resultAdapter;
    private List<ScreenResult> mResult = new ArrayList<>();
    /**
     * 初始化presenter，也是与Activity的绑定
     *
     * @return 返回new的Presenter层的值
     */
    @Override
    protected HistoryPresenter createPresenter() {
        return new HistoryPresenter(this);
    }

    /**
     * 载入view的一些操作
     */
    @Override
    protected void initView() {
        binding.hisRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    /**
     * 载入数据操作
     */
    @Override
    protected void initData() {

    }

    /**
     * {@inheritDoc}
     * <p>
     * Dispatch onResume() to fragments.  Note that for better inter-operation
     * with older versions of the platform, at the point of this call the
     * fragments attached to the activity are <em>not</em> resumed.
     */
    @Override
    protected void onResume() {
        super.onResume();
        presenter.getResultList();
    }

    /**
     * 在这里要返回view的根路径
     *
     * @return 返回绑定的view
     */
    @Override
    protected View getRootView() {
        binding = ActivityHistoryBinding.inflate(getLayoutInflater());
        return binding.getRoot();
    }

    @Override
    public void setResultData(List<ScreenResult> list) {
        mResult = list;
        resultAdapter = new ResultAdapter(R.layout.item_his_list,list);
        binding.hisRecyclerView.setAdapter(resultAdapter);
        resultAdapter.setOnItemClickListener((adapter, view, position) -> {
            int path = mResult.get(position).getPath();
            double min = mResult.get(position).getMin();
            double r = mResult.get(position).getR();
            double jd = mResult.get(position).getJd();
            double interval = mResult.get(position).getInterval();
            double xxx = mResult.get(position).getXxx();
            double jdx = mResult.get(position).getJdx();
            double jdy = mResult.get(position).getJdy();
            double jdZy =  mResult.get(position).getJdZy();
            // TODO: 2022/5/14 在下面空的case处填好对应的计算方法
            switch (path){
                case GlobalConstant.CCDM:
                    InputModel.ypjCompute(min,r,jd,interval);
                    break;
                case GlobalConstant.MCDM:
                    InputModel.hpjCompute(min, r, jd, interval,xxx);
                    break;
                case GlobalConstant.CCTS:
                    InputModel.yqxCompute(min, r, jd, interval);
                    break;
                case GlobalConstant.MCTS:
                    InputModel.hqxCompute(min,r,jd,interval,xxx);
                    break;
                case GlobalConstant.CCPV:
                    InputModel.yjiCompute(min,r,jd,interval,jdx,jdy,jdZy);
                    break;
                case GlobalConstant.MCPV:
                    InputModel.hjiCompute(min,r,jd,interval,jdx,jdy,jdZy,xxx);
                    break;
                case GlobalConstant.CCCS:
                    InputModel.ycsCompute(min,r,jd,interval,jdx,jdy,jdZy);
                    break;
                case GlobalConstant.MCCS:
                    InputModel.hcsCompute(min,r,jd,interval,jdx,jdy,jdZy,xxx);
                    break;
                default:
                    break;
            }
            presenter.visitHistory(path);
        });
    }

    @Override
    public void doSuccess(int path) {
        switch (path) {
            case GlobalConstant.CCDM:
                ActivityUtil.actionThirdStart(ResultActivity.class, GlobalConstant.CIRCULAR_CURVE, GlobalConstant.DECLINATION_METHOD, path);
                break;
            case GlobalConstant.MCDM:
                ActivityUtil.actionThirdStart(ResultActivity.class, GlobalConstant.MODERATION_CURVE, GlobalConstant.DECLINATION_METHOD, path);
                break;
            case GlobalConstant.CCTS:
                ActivityUtil.actionThirdStart(ResultActivity.class, GlobalConstant.CIRCULAR_CURVE, GlobalConstant.TANGENT_SUPPORT_METHOD, path);
                break;
            case GlobalConstant.MCTS:
                ActivityUtil.actionThirdStart(ResultActivity.class, GlobalConstant.MODERATION_CURVE, GlobalConstant.TANGENT_SUPPORT_METHOD, path);
                break;
            case GlobalConstant.CCPV:
                ActivityUtil.actionThirdStart(ResultActivity.class, GlobalConstant.CIRCULAR_CURVE, GlobalConstant.POLAR_COORDINATE_METHOD, path);
                break;
            case GlobalConstant.MCPV:
                ActivityUtil.actionThirdStart(ResultActivity.class, GlobalConstant.MODERATION_CURVE, GlobalConstant.POLAR_COORDINATE_METHOD, path);
                break;
            default:
                break;
        }
    }

}